module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {
            options: {},
            build: ['build', 'dist']
        },
        babel: {
            options: {
                sourceMap: false,
                presets: ['es2015']
            },
            dist: {
                files: {
                    'build/app.js': 'app.js',
                    'build/app.config.js': 'app.config.js'
                }
            }
        },
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            build: {
                files: {
                    'dist/app.min.js': ['build/app.js']
                }
            }
        },
        copy: {
            main: {
                files: [
                    // includes files within path
                    { expand: true, flatten: true, src: ['build/app.config.js'], dest: 'dist/', filter: 'isFile' },
                    { expand: true, src: ['public/**'], dest: 'dist/' }
                ]
            }
        }
    })

    // 加载提供"uglify"任务的插件
    grunt.loadNpmTasks('grunt-contrib-clean')
    grunt.loadNpmTasks('grunt-babel')
    grunt.loadNpmTasks('grunt-contrib-uglify')
    grunt.loadNpmTasks('grunt-contrib-copy')

    // 默认任务
    grunt.registerTask('default', ['clean', 'babel', 'uglify', 'copy'])
}
